package com.powernode.feign;

import com.powernode.dto.CategoryDto;
import com.powernode.dto.ProductDto;
import com.powernode.dto.Result;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 远程调用失败时，执行容错逻辑
 **/
@Component
public class FeignPMSFallBack implements FallbackFactory<PMSFeign> {
    @Override
    public PMSFeign create(Throwable cause) {
        return new PMSFeign() {
            @Override
            public Result getProductById(Long productId) {
                return Result.failure(-400,"数据有误");
            }

            @Override
            public Result<CategoryDto> getCategoryById(Long categoryId) {
                return Result.failure(-400,"数据有误");
            }

            @Override
            public Result<List<ProductDto>> listProductsByIds(List<Long> productIds) {
                return Result.failure(-400,"数据有误");
            }

            @Override
            public Result<List<CategoryDto>> listCategoriesByLevel(Integer level) {
                return Result.failure(-400,"数据有误");
            }

            @Override
            public Result edit(ProductDto productDto) {
                return Result.failure(-400,"数据有误");
            }

            @Override
            public Result decrStock(Long productId, Integer num) {
                return Result.failure(-400,"数据有误");
            }

            @Override
            public Result incrStock(Long productId, Integer num) {
                return Result.failure(-400,"数据有误");
            }
        };
    }
}
